﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.Profile;
using umbraco;
using CommerceForUmbraco.profile;
using umbraco.cms.businesslogic.member;
using umbraco.cms.businesslogic.propertytype;



namespace CommerceForUmbraco.usercontrols.usercontrols.commerce
{
    public partial class PWChangePassword : System.Web.UI.UserControl
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            this.ctrlAdditionalValidationMessageLabel.Text = "";

        }

        protected void ctrlChangeBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.ctrlPasswordBox.Text == "" ||
                     this.ctrlPasswordConfirmBox.Text == "")
                {
                    this.ctrlAdditionalValidationMessageLabel.Text = "You must enter your password and password confirmation.";
                    return;
                }

                Member member = null;

                member = Member.GetCurrentMember();

                member.ChangePassword(this.ctrlPasswordBox.Text);

                member.Save();

                //to user saying thank you
                MessagingController.SendChangedPasswordEmail(member.Text, member.Email);
            }
            catch (Exception x)
            {
                this.ctrlAdditionalValidationMessageLabel.Text = string.Format("Error - unable to create or modify your account password. Exception Details: {1}", x.Message);
                return;
            }

            this.ctrlSuccessMessageLabel.Text = "Success!  Your password was successfully updated.";
            this.ctrlChangePassPanel.Visible = false;
        }
    }
}